/*
    YmsgIRC - Program enabling YMSG chat clients to use IRC
    Copyright (C) 2011 Crash Daemonicus ( crashenator -at- gmail.com )

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "main.h"

#include <vector>



int main(int argc, char *argv[])
{

    dbg_head("main(int argc, char *argv[])");
    license_display_notice();

	vector<YmsgField> fields=	YmsgList(318,
									 YmsgItem(318,
			 							 YmsgField(65,"YmsgIRC Group")
			 							+YmsgList(319,
			 								 YmsgItem(319,YmsgField(7,NW_RESERVED_USERNAME))
			 								+YmsgItem(319,YmsgField(7,"NickServ"))
			 								+YmsgItem(319,YmsgField(7,"username"))
			 							 ).toFields()
									 )
								 )
								 +YmsgList(320,
									  YmsgItem(320,YmsgField(7,"dummy_ignore_entry0"))
									 +YmsgItem(320,YmsgField(7,"dummy_ignore_entry1"))
								 ).toFields();


	YmsgPacket pkt(fields,0x00F1);

	YmsgFieldParser parser;
	parser.debugObjects(parser.getObjects(pkt.contentObject.fields));
	//dbg_vec(pkt.contentObject.fields);

    
    bool ready;
    
    Proxy px;
    ready=px.Startup();
    
    
    #ifdef COMMON_DBG
        puts("\n---- Beginning Processing Debug ---");
		/*string fields="1\xC0\x80value\xC0 A\x80 1\xC0\x80 2\xC0\x80value2\xC0\x80 3\xC0\x80value3\xC0\x80";
		YmsgPacket pkt(fields,0x00A8);
		foreach_vector(const YmsgField,it,pkt.contentObject.fields)
		{
			printf("\n Field: {%d} = {%s} \n",  (*it).num,  (*it).value.c_str() );
		}*/

        IrcCommand ic(":hubbard.freenode.net 353 CrashIRCx @ #test :CrashIRCx +blueyed +phil_s_stein +pols +kopakrraf +Dave158");
        ic.process();
        ic.debug();
        puts("---- Processing Debug Finished ---\n");
    #endif
    
    px.ymsg.NwAConnInfo("127.0.0.1",5050);
    px.irc.NwAConnInfo("irc.freenode.net",6667);
    if(ready) ready=px.stepsBegin();
    while(ready)
    {
        px.step();
        Sleep(25);
    }
    puts("***Quitting...");
    px.stepsEnd();
    px.Shutdown();
    
    ReturnD(EXIT_SUCCESS);
}
